//
//  YZReservationView.m
//  患者信息界面（代码）
//
//  Created by Yip-Jun on 16/5/10.
//  Copyright © 2016年 YIPWJ. All rights reserved.
//

#import "YZReservationView.h"
#import "Masonry.h"
#import "YZDoctorModel.h"

#define YZReservationViewLabelSize 16

@interface YZReservationView ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *diseaseLabel;
@property (nonatomic, strong) UILabel *sickLabel;
@property (nonatomic, strong) UILabel *reservationLabel;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *hospitalLabel;
@property (nonatomic, strong) UILabel *hospitalNameLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *costLabel;
@property (nonatomic, strong) UILabel *chargeLabel;
@property (nonatomic, strong) UILabel *promptLabel;

@property (nonatomic, strong) UIView *lineViewV;
@property (nonatomic, strong) UIView *lineViewH;

@property (nonatomic, strong) UIButton *cannelButton;
@property (nonatomic, strong) UIButton *correctButton;

@end

@implementation YZReservationView

+ (instancetype)reservationView:(YZDoctorModel *)doctorModel {
    YZReservationView *reservationView = [[YZReservationView alloc] init];
    
    reservationView.backgroundColor = [UIColor whiteColor];
    reservationView.layer.cornerRadius = 15;
    reservationView.layer.masksToBounds = YES;

    [reservationView prepareUI];
    [reservationView layoutSubviewsContraint];

    reservationView.nameLabel.text = doctorModel.doctor_name;
    reservationView.hospitalNameLabel.text = doctorModel.doctor_hospital_name;
    
    return reservationView;
}

- (void)prepareUI {
  
    [self addSubview:self.titleLabel];
    [self addSubview:self.diseaseLabel];
    [self addSubview:self.sickLabel];
    [self addSubview:self.reservationLabel];
    [self addSubview:self.nameLabel];
    [self addSubview:self.hospitalLabel];
    [self addSubview:self.hospitalNameLabel];
    [self addSubview:self.dateLabel];
    [self addSubview:self.timeLabel];
    [self addSubview:self.costLabel];
    [self addSubview:self.chargeLabel];
    [self addSubview:self.promptLabel];
    [self addSubview:self.lineViewV];
    [self addSubview:self.lineViewH];
    [self addSubview:self.cannelButton];
    [self addSubview:self.correctButton];
}

- (void)layoutSubviewsContraint {
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self).offset(16);
    }];
    
    [self.diseaseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(16);
        make.leading.equalTo(self).offset(16);
    }];
    
    [self.sickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.diseaseLabel);
        make.leading.equalTo(self.diseaseLabel.mas_trailing).offset(32);
    }];

    [self.reservationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.diseaseLabel.mas_bottom).offset(16);
        make.leading.equalTo(self).offset(16);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.reservationLabel);
        make.leading.equalTo(self.reservationLabel.mas_trailing).offset(32);
    }];
    
    [self.hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.reservationLabel.mas_bottom).offset(16);
        make.leading.equalTo(self).offset(16);
    }];
    
    [self.hospitalNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.hospitalLabel);
        make.leading.equalTo(self.hospitalLabel.mas_trailing).offset(32);
    }];

    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.hospitalLabel.mas_bottom).offset(16);
        make.leading.equalTo(self).offset(16);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dateLabel);
        make.leading.equalTo(self.dateLabel.mas_trailing).offset(32);
    }];
    
    [self.costLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.dateLabel.mas_bottom).offset(16);
        make.leading.equalTo(self).offset(16);
    }];
    
    [self.chargeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.costLabel);
        make.leading.equalTo(self.costLabel.mas_trailing).offset(32);
    }];
    
    [self.promptLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.costLabel.mas_bottom).offset(16);
        make.leading.equalTo(self).offset(16);
        make.trailing.equalTo(self).offset(-16);
    }];
    
    [self.lineViewV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).offset(-44);
        make.leading.trailing.equalTo(self);
        make.height.mas_equalTo(1);
    }];
    
    [self.lineViewH mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.lineViewV.mas_bottom);
        make.bottom.equalTo(self);
        make.width.mas_equalTo(1);
    }];
    
    [self.cannelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineViewV).offset(8);
        make.bottom.equalTo(self).offset(-8);
        make.leading.equalTo(self).offset(16);
        make.trailing.equalTo(self.lineViewH).offset(-16);
    }];
    
    [self.correctButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineViewV).offset(8);
        make.bottom.equalTo(self).offset(-8);
        make.leading.equalTo(self.lineViewH).offset(16);
        make.trailing.equalTo(self).offset(-16);
    }];
}

- (void)cannelButtonDidClick {
    self.cannelButtonDidClickBlock();
}

- (void)correctButtonDidClick {
    NSLog(@"你点击了提交按钮（correctButtonDidClick），因为不知道提交到哪里去，所以调用了（cannelButtonDidClick）");
    [self cannelButtonDidClick];
}

#pragma mark - 懒加载
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"预约信息确认";
        _titleLabel.textColor = [UIColor blueColor];
        _titleLabel.font = [UIFont systemFontOfSize:18];
    }
    return _titleLabel;
}

- (UILabel *)diseaseLabel {
    if (!_diseaseLabel) {
        _diseaseLabel = [[UILabel alloc] init];
        _diseaseLabel.text = @"疾病类型：";
        _diseaseLabel.textColor = [UIColor lightGrayColor];
        _diseaseLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
    }
    return _diseaseLabel;
}

- (UILabel *)sickLabel {
    if (!_sickLabel) {
        _sickLabel = [[UILabel alloc] init];
        _sickLabel.text = @"肿瘤";
        _sickLabel.textColor = [UIColor blackColor];
        _sickLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
    }
    return _sickLabel;
}

- (UILabel *)reservationLabel {
    if (!_reservationLabel) {
        _reservationLabel = [[UILabel alloc] init];
        _reservationLabel.text = @"预约医生：";
        _reservationLabel.textColor = [UIColor lightGrayColor];
        _reservationLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
    }
    return _reservationLabel;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
//        _nameLabel.text = @"王远";
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
    }
    return _nameLabel;
}

- (UILabel *)hospitalLabel {
    if (!_hospitalLabel) {
        _hospitalLabel = [[UILabel alloc] init];
        _hospitalLabel.text = @"坐诊医院：";
        _hospitalLabel.textColor = [UIColor lightGrayColor];
        _hospitalLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
    }
    return _hospitalLabel;
}

- (UILabel *)hospitalNameLabel {
    if (!_hospitalNameLabel) {
        _hospitalNameLabel = [[UILabel alloc] init];
//        _hospitalNameLabel.text = @"北京大学人民医院";
        _hospitalNameLabel.textColor = [UIColor blackColor];
        _hospitalNameLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
    }
    return _hospitalNameLabel;
}

- (UILabel *)dateLabel {
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.text = @"就诊日期：";
        _dateLabel.textColor = [UIColor lightGrayColor];
        _dateLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
    }
    return _dateLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.text = @"2016-02-01 下午";
        _timeLabel.textColor = [UIColor blackColor];
        _timeLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
    }
    return _timeLabel;
}

- (UILabel *)costLabel {
    if (!_costLabel) {
        _costLabel = [[UILabel alloc] init];
        _costLabel.text = @"门诊费用：";
        _costLabel.textColor = [UIColor lightGrayColor];
        _costLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
    }
    return _costLabel;
}

- (UILabel *)chargeLabel {
    if (!_chargeLabel) {
        _chargeLabel = [[UILabel alloc] init];
        _chargeLabel.text = @"7 元";
        _chargeLabel.textColor = [UIColor redColor];
        _chargeLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
    }
    return _chargeLabel;
}

- (UILabel *)promptLabel {
    if (!_promptLabel) {
        _promptLabel = [[UILabel alloc] init];
        _promptLabel.numberOfLines = 0;
        _promptLabel.text = @"[温馨提示] 门诊费用只提供参考，具体给用以医院时间价格为准";
        _promptLabel.textColor = [UIColor colorWithRed:37 / 255.0 green:199 / 255.0 blue:199 / 255.0 alpha:1];
        _promptLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
    }
    return _promptLabel;
}

- (UIButton *)cannelButton {
    if (!_cannelButton) {
        _cannelButton = [[UIButton alloc] init];
        _cannelButton.titleLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
        [_cannelButton setTitle:@"取消" forState:UIControlStateNormal];
        [_cannelButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [_cannelButton addTarget:self action:@selector(cannelButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cannelButton;
}

- (UIButton *)correctButton {
    if (!_correctButton) {
        _correctButton = [[UIButton alloc] init];
        _correctButton.titleLabel.font = [UIFont systemFontOfSize:YZReservationViewLabelSize];
        [_correctButton setTitle:@"提交" forState:UIControlStateNormal];
        [_correctButton setTitleColor:[UIColor  colorWithRed:37 / 255.0 green:199 / 255.0 blue:199 / 255.0 alpha:1] forState:UIControlStateNormal];
        [_correctButton addTarget:self action:@selector(correctButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _correctButton;
}

- (UIView *)lineViewV {
    if (!_lineViewV) {
        _lineViewV = [[UIView alloc] init];
        _lineViewV.backgroundColor = [UIColor grayColor];
    }
    return _lineViewV;
}

- (UIView *)lineViewH {
    if (!_lineViewH) {
        _lineViewH = [[UIView alloc] init];
        _lineViewH.backgroundColor = [UIColor grayColor];
    }
    return _lineViewH;
}

@end
